﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.ComponentModel;
using System.Threading;

namespace DisplayBoardInfo.Server.Forms.CustomComponents
{
    public class FormDialog : Form
    {
        BackgroundWorker bw;

        public FormDialog()
        {
            this.Load += new EventHandler(FormDialog_Load);
            bw = new BackgroundWorker();
            bw.DoWork += new DoWorkEventHandler(bw_DoWork);
            bw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bw_RunWorkerCompleted);
        }

        void bw_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            this.Cursor = Cursors.Arrow;
            EnabledAllComponents(true);
        }

        void bw_DoWork(object sender, DoWorkEventArgs e)
        {
            InitlializeForm();
        }

        void FormDialog_Load(object sender, EventArgs e)
        {
            this.Cursor = Cursors.WaitCursor;
            EnabledAllComponents(false);
            bw.RunWorkerAsync();
        }

        private void EnabledAllComponents(bool enabled)
        {
            foreach (Control item in this.Controls)
            {
                item.Enabled = enabled;
            }
        }

        /// <summary>
        /// Initializes all form data and settings.
        /// </summary>
        protected virtual void InitlializeForm()
        { 
        
        }

    }
}
